﻿using System.Collections.Generic;
using System.IO;
using Framework;
using UnityEditor;
using UnityEngine;

namespace FrameworkEditor
{
    internal class OneToOneNoShare : IAbSetting
    {
        internal OneToOneNoShare(string path, string regex) : base(path, regex)
        {
        }

        internal override List<AssetBundleBuild> GetAllBuilders()
        {
            var ret = new List<AssetBundleBuild>();
            if (string.IsNullOrEmpty(DirPath))
            {
                return ret;
            }

            if (!Directory.Exists(DirPath))
            {
                Debug.Log("OneToOneNoShare DirPath = " + DirPath + " does not exists!");
                return ret;
            }

            foreach (var file in Directory.GetFiles(DirPath, "*.*", SearchOption.TopDirectoryOnly))
            {
                if (!IsNeedBuild(file))
                {
                    continue;
                }

                var assetPath = EditorUtils.GetPathRelativeToAssets(file);
                var abName = EditorUtils.GetRelativePathToDir(assetPath, EditorUtils.assetRootDir) + FrameworkSettings.AssetBundleExt;
                //Debug.Log("OneToOneNoShare abName = " + abName + " assetPath = " + assetPath);
                ret.Add(new AssetBundleBuild
                {
                    assetBundleName = abName,
                    assetNames = new[] { assetPath }
                });
            }

            return ret;
        }
    }
}